{{#if is_web_site}}
use askama::Template;
{{/if}}
{{#if is_web_site}}
use salvo::{oapi::endpoint, writing::Text, Request, Response};
{{else}}
use salvo::oapi::endpoint;
{{/if}}
use crate::app_writer::AppResult;
{{#if is_web_site}}

#[derive(Template)]
#[template(path = "hello.html")]
struct HelloTemplate<'a> {
    name: &'a str,
}

#[endpoint]
pub async fn hello(req: &mut Request, res: &mut Response)->AppResult<()>{
    let hello_tmpl = HelloTemplate {
        name: req.param::<&str>("name").unwrap_or("World"),
    };
    res.render(Text::Html(hello_tmpl.render().unwrap()));
    Ok(())
}
{{else}}
#[endpoint]
pub async fn hello() -> AppResult<&'static str> {
    Ok("Hello World from salvo")
}
{{/if}}

#[allow(unused_imports)]
mod tests {
    use salvo::test::{ResponseExt, TestClient};
    use salvo::Service;
    use crate::config::CFG;

    #[tokio::test]
    async fn test_hello_world() {
        let service = Service::new(crate::routers::router());

        let content = TestClient::get(format!(
            "http://{}",
            &CFG.server.address.replace("0.0.0.0", "127.0.0.1")
        ))
        .send(&service)
        .await
        .take_string()
        .await
        .unwrap();
        assert_eq!(content, "Hello World from salvo");
    }
}
